package com.taobao.txc.resourcemanager.d;

import com.taobao.txc.a.b.e;
import com.taobao.txc.a.b.f;
import com.taobao.txc.a.b.g;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.c.B;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@ChannelHandler.Sharable
public class b
  extends g
  implements com.taobao.txc.resourcemanager.a
{
  private static final LoggerWrap t = LoggerInit.logger;
  
  public void b()
  {
    this.m.scheduleAtFixedRate(new c(this), 30L, 60L, TimeUnit.SECONDS);
    super.a(30L, 60L);
  }
  
  public void a(String paramString)
  {
    super.a(paramString + "_rt");
  }
  
  protected String b(String paramString)
  {
    throw new RuntimeException("unsupprted method!");
  }
  
  public Channel c(String paramString)
  {
    Object localObject1 = (Channel)this.b.get(paramString);
    if (localObject1 != null)
    {
      if (((Channel)localObject1).isActive()) {
        return localObject1;
      }
      for (int i = 0; i < 1000; i++)
      {
        try
        {
          Thread.sleep(10L);
        }
        catch (InterruptedException localInterruptedException) {}
        if (((Channel)localObject1).isActive()) {
          return localObject1;
        }
      }
      try
      {
        t.warn("channel " + localObject1 + " is not active after long wait, close it.");
        Object localObject2 = this.a.get(paramString);
        if (localObject2 == null)
        {
          this.a.putIfAbsent(paramString, new Object());
          localObject2 = this.a.get(paramString);
        }
        synchronized (localObject2)
        {
          Channel localChannel1 = (Channel)this.b.get(paramString);
          if ((localChannel1 != null) && (localChannel1.compareTo(localObject1) == 0))
          {
            this.b.remove(paramString);
            ((Channel)localObject1).disconnect();
            ((Channel)localObject1).close();
          }
        }
      }
      catch (Exception localException1)
      {
        localException1 = localException1;
      }
      finally {}
    }
    String str = com.taobao.txc.resourcemanager.b.b.c();
    if ((str == null) || (str.length() == 0)) {
      throw new com.taobao.txc.common.b.c(B.b.a(), "can not register RM because no dbkey found.");
    }
    t.info("connect to " + paramString);
    ??? = this.a.get(paramString);
    if (??? == null)
    {
      this.a.putIfAbsent(paramString, new Object());
      ??? = this.a.get(paramString);
    }
    synchronized (???)
    {
      Channel localChannel2 = super.e(paramString);
      try
      {
        t.info("RM will register dbkey:" + str);
        e locale = new e(str);
        locale.a((short)com.taobao.txc.common.a.c.a());
        Object localObject5 = super.a(null, localChannel2, locale, 30000L);
        if ((localObject5 instanceof f))
        {
          localObject1 = localChannel2;
          this.b.put(paramString, localObject1);
          if (((f)localObject5).d()) {
            t.info("register RM sucesss. server version:" + ((f)localObject5).b());
          } else {
            t.info("register RM failed. server version:" + ((f)localObject5).b());
          }
          return localObject1;
        }
        throw new com.taobao.txc.common.b.c(B.b.a(), "can not register RM.");
      }
      catch (Exception localException2)
      {
        t.a(com.taobao.txc.common.b.b.P.bd, "register RM failed.", localException2);
        throw new com.taobao.txc.common.b.c(B.b.a(), "can not register RM.");
      }
    }
  }
  
  public void a(long paramLong, String paramString, Object paramObject)
  {
    t.info("RmRpcClient sendResponse" + paramObject);
    super.a(paramLong, c(paramString), paramObject);
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.d.b
 * JD-Core Version:    0.7.0.1
 */